/******************************************************************************************
 * Import
 ******************************************************************************************/

// module
import Taro, { Component } from '@tarojs/taro'

// project
import { CPage, CContent, CHeader, CFooter, CFloat, CAround, CBetween, CCenter, CRow, CWrap, CLine, CHand, CItemX, CItemY, CText, CLabel, CSvg, CImage, CButton, CColumn } from '../../library/comp';
import { Base64, Gen, Time, Zip, Session, Storage, Http } from '../../library/func';
import Icon from '../../project/style/icon';
import DoHttp from '../../project/func/http/http'


/******************************************************************************************
 * Export Class
 ******************************************************************************************/

export default class Index extends Component {

	/*------------------------------------------------------------------------------------
	 * 初始化
	 *-----------------------------------------------------------------------------------*/
	constructor(props) {
		super(props);

		/**
		 * state
		 */
		this.state = {
			id:2,
			orderid:'QWMN1541829941',
			is_pay:false,
			amount:149,
		}
	}

	/*------------------------------------------------------------------------------------
	 * 生命周期
	 *-----------------------------------------------------------------------------------*/
	// willMount
	componentWillMount() {
		this.setState({
			id:this.$router.params.id,
			is_pay:this.$router.params.ispay
		})
	}
	// didMount
	componentDidMount() {
		// 接口 获取订单信息：订单额与订单编号
		DoHttp.get({
			url:'order/detail.php',
			data:{
				id:this.state.id,
			},
			success:(data) => {
				this.setState({
					amount:data.order.set_amount,
					orderid:data.order.set_orderid,
				})
				console.log('获取订单信息 成功',data)
			}
		})

		// 如果支付成功，改变订单状态
		if(this.state.is_pay){
			DoHttp.post({
				url:'order/logic/ok.php',
				data:{
					orderid:this.state.orderid
				},
				success:(data) => {
					console.log('datadatadatadatadatadata',data)
				},
				error:(err) => {
					console.log('errerrerrerrerrerrerrerrerrerr',err)
				}
			})
			console.log('this.state.orderid',this.state.orderid)
		}
	}
	
	/*------------------------------------------------------------------------------------
	 * 事件处理
	 *-----------------------------------------------------------------------------------*/
	// onClick
	onClick = (id, e)=> {
		console.log('onClick: ' + id)
    }
    
    // onRedirect
    onRedirect = (url, e)=> {
        wx.redirectTo({
            url: url
        })
    }

	/*------------------------------------------------------------------------------------
	 * 自定义方法
	 *-----------------------------------------------------------------------------------*/

	/*------------------------------------------------------------------------------------
	 * 渲染
	 *-----------------------------------------------------------------------------------*/
	render () {
		return (
			<CPage>
				<CContent>
					{
							 
						this.state.is_pay ?
						// 成功页面
						(
							<CColumn>
								{/* 成功图标 */}
								<CRow pb='33' pt='70' bg='#fff' x='center'>
									<CImage w='164' h='164' src='http://image.mod.hesq.com.cn/rushbuy/assets/20181113/paymentsuccess.png'></CImage>
								</CRow>

								{/* 成功文字 */}
								<CRow pb='16' bg='#fff' x='center' color='#3eb737' size='32' >支付成功</CRow>

								{/* 总价 */}
								<CRow pb='37' bg='#fff' x='center' color='#333' size='70' >{this.state.amount}元</CRow>

								{/* 查看订单、继续逛逛 */}
								<CAround px='28'>
									<CHand bg='#d13824' size='28' ra='35' w='187' h='70' lh='70' color='#fff' x='center' 
										onClick={this.onRedirect.bind(this,'/screen/user/order/list?status=全部')}
									>查看订单</CHand>
									<CHand bg='#d13824' size='28' ra='35' w='187' h='70' lh='70' color='#fff' x='center'
										onClick={this.onRedirect.bind(this,'/screen/home/index')}
									>继续逛逛</CHand>
								</CAround>
							</CColumn>
						) 
						:
						// 失败页面
						(
							<CColumn>
								{/* 失败图标 */}
								<CRow pb='33' pt='70' bg='#fff' x='center'>
									<CImage w='164' h='164' src='http://image.mod.hesq.com.cn/rushbuy/assets/20181113/paymenterror.png'></CImage>
								</CRow>

								{/* 失败文字 */}
								<CRow bg='#fff' x='center' color='#d13824' size='32' >支付失败</CRow>

								{/* 总价 */}
								{
									this.state.amount ? (
										<CRow bg='#fff' mt='37' x='center' color='#333' size='70' >{this.state.amount}元</CRow>
									) : (null)
								}
								

								{/* 去付款、继续逛逛 */}
								<CAround px='28' mt='70'>
									<CHand bg='#d13824' size='28' ra='35' w='187' h='70' lh='70' color='#fff' x='center' 
										onClick={this.onRedirect.bind(this,'/screen/user/order/list?status=未付款')}
									>去付款</CHand>
									<CHand bg='#d13824' size='28' ra='35' w='187' h='70' lh='70' color='#fff' x='center'
										onClick={this.onRedirect.bind(this,'/screen/home/index')}
									>继续逛逛</CHand>
								</CAround>
							</CColumn>
						)
					}


					
					

				</CContent>
			</CPage>
		)
	}
}


